package cn.stylefeng.guns.modular.business.common;

import cn.stylefeng.guns.modular.business.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author zhangf
 */
@Slf4j
@Component
public class TokenTask {

    @Autowired
    AccountService accountService;

    /**
     * 获取微信access_token
     */
    @Scheduled(fixedDelay = 60 * 60 * 1000)
    void setServerToken() {
        //设置access—token
        final String accessToken = accountService.getWxToken();
        TokenSingleton.getTokenSingleton().setWeixinToken(accessToken);
        // 打印 Token 日志
        log.info("微信access_token设置完成,当前凭证:{}", TokenSingleton.getTokenSingleton());
    }
}
